import time

from selenium import webdriver
from selenium.webdriver.common.by import By
import os

driver = webdriver.Chrome()
file = "file:///" + os.path.abspath("html") + "/frame.html"
driver.get(file)

# 切换到指定frame   f1
driver.switch_to.frame("f1")
inner_h3 = driver.find_element(By.ID, "inner_h3")
print(inner_h3.get_attribute("outerHTML"))

# 切换frame f2
f2 = driver.find_element(By.ID, 'f2')
driver.switch_to.frame(f2)
print(driver.find_element(By.ID, 'p1').get_attribute("outerHTML"))

# 切换到父级
driver.switch_to.parent_frame()
print(driver.find_element(By.ID, 'f2').get_attribute('outerHTML'))

# 切换到主页面
driver.switch_to.default_content()
print(driver.find_element(By.TAG_NAME, "h3").get_attribute("outerHTML"))


time.sleep(2)
driver.quit()
